#pragma once

#include <optixu/optixu_math_namespace.h>
#include <optixu/optixu_vector_types.h>

using namespace optix;

 __device__ __inline__ void sample_direction(const float3& ffnormal, const float z1, const float z2, const float exponent, float3& dir) 
 {
    float z3 = powf(fold(z1), 2.0f / (exponent + 1.0f));
    float sintheta = sqrtf(1.0f - z3);
    float costheta = sqrtf(z3);
    float phi = (2.0f * M_PIf) * z2;
    float cosphi = cosf(phi) * sintheta;
    float sinphi = sinf(phi) * sintheta;
    float3 v1, v2;
    create_onb(ffnormal, v1, v2);
    dir = ffnormal * costheta + v1 * cosphi + v2 * sinphi;
 }


